//key值：	  BVNBZ-6LN63-I6M3X-Y67SS-C35S7-ZHBGG

import qqmap from '../../../utils/qqmap'

Page({
  data: {
    address: '',
    points: ''
  },
  async onLoad() {
    // wx.getLocation({
    //   success(res) {
    //     console.log(res);
    //   },
    //   fail(err) {
    //     console.log(err);
    //   }
    // })
    const res = {
      latitude: 23.216864,
      longitude: 116.490206
    }
    // const { latitude, longitude } = await wx.getLocation({})
    this.reverseGeocoder(res.latitude, res.longitude)
  },
  reverseGeocoder(latitude, longitude) {
    qqmap.reverseGeocoder({
      location: {
        latitude: latitude,
        longitude: longitude
      },
      success: (geoResult) => {
        this.setData({
          address: geoResult.result.address
        }),
          qqmap.search({
            keyword: '小区',
            location: {
              latitude: latitude,
              longitude: longitude
            },
            success: (searchResult) => {
              // console.log(433, searchResult);
              this.setData({
                points: searchResult.data.map((v) => ({ id: v.id, title: v.title }))
                // points: searchResult.data
              })
              // console.log(444, this.data.points);
            },
            fail: (searchErr) => {
              console.log(searchErr);
            }
          })
      },
      fail: (err) => {
        console.log(err);
      }
    })
  },
  async onChooseAddress() {
    // const { latitude, longitude } = await wx.chooseLocation({})
    const res = {
      latitude: 23.216864,
      longitude: 116.490206
    }
    this.reverseGeocoder(res.latitude, res.longitude)
  }

})